package edu.cmu.cs211.exprtree.tests;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import static edu.cmu.cs211.exprtree.tests.ExpressionTestUtil.*;

public class AddExpressionTest {

  @Test
  public void testCfold0()
  {
    cfoldtest("5+6", "11");
    cfoldtest("0.0+x+1", "x+1");
    cfoldtest("x+0.0+1", "x+1");
    cfoldtest("5+x", "5+x");
    cfoldtest("x+5", "x+5");
  }
  
  @Test
  public void testCfold4() {
	cfoldtest("(x+1)+(x+0)+(x+0)", "(x+1)+x+x");
    cfoldtest("(5+6)+(5+6)", "22");
	cfoldtest("((x+1)+(0))", "x+1");  
    cfoldtest("((x+1)+(0+0))", "x+1");
    cfoldtest("(0+0)+(x+1)", "x+1");
    cfoldtest("1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1", "20");
  }
  
	@Test
	public void evalNoVars() {
		/* Construct the variable map */
		Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
		
		/* test the evaluate function with no variables */
		ExpressionTestUtil.evaluatetest("5+6", "11", map);
		ExpressionTestUtil.evaluatetest("(5+6)+(5+6)", "22", map);
		ExpressionTestUtil.evaluatetest("1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1", "20", map);
	}
	
	@Test
	public void evalVars() {
		/* Construct the variable map (maybe we could do this dynamically in a loop for 
		 * a more "stressful" test?)
		 */
		Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
		map.put("y", new BigDecimal("-1343946635"));
		map.put("x", new BigDecimal("1505156470"));
		
		/* test the evalaute function with the current variable mapping */
		ExpressionTestUtil.evaluatetest("5+x", "1505156475", map);
	/*	ExpressionTestUtil.evaluatetest("x+5", "12", map);
		ExpressionTestUtil.evaluatetest("0+x", "7", map);
		ExpressionTestUtil.evaluatetest("0.0+x", "7.0", map);
		ExpressionTestUtil.evaluatetest("0.1+x", "7.1", map);
		ExpressionTestUtil.evaluatetest("x+0", "7", map);
		ExpressionTestUtil.evaluatetest("x+0.0", "7.0", map);
		ExpressionTestUtil.evaluatetest("x+0.1", "7.1", map);
		ExpressionTestUtil.evaluatetest("(0+0)+x", "7", map);
		ExpressionTestUtil.evaluatetest("x+(0+0)", "7", map);
		ExpressionTestUtil.evaluatetest("(0+1)+x", "8", map);
		ExpressionTestUtil.evaluatetest("x+(1+0)", "8", map);
		ExpressionTestUtil.evaluatetest("(x+1)+(0+0)", "8", map);
		ExpressionTestUtil.evaluatetest("(0+0)+(x+1)", "8", map);*/
	}
}
